@extends('public.layouts')
@section('style')
    <meta name="_token" content="{{ csrf_token() }}"/>
    <style>
        .task-th {
            text-align: center;
        }

        .task-td {
            text-align: center;
        }
    </style>
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap-datetimepicker.min.css')}}">
    <link rel="stylesheet" href="{{asset('admin_assets/css/bootstrap.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/fileinput.min.css')}}">
    <link rel="stylesheet" href="{{url('admin_assets/css/ip.css')}}">
    <link rel="stylesheet" href="{{url('css/search.css')}}">
@stop
@section('content')
    <div class="content-wrapper" style="background-color: white">
        <section class="content">
            <div class="row">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="box box-info"
                         style="padding-top: 0px;margin-top: 0px;border-top: 0px;border-bottom: solid 1px #0080ff;">
                        <div class="box-body" style="">
                            <div class="row" style="max-height: 50px">
                                <div class="col-lg-2 col-md-2 col-sm-12 col-xs-12" style="margin-top: 1%">
                                    <a href="#" title="返回首页" style="float: left"><i class="fa fa-home fa-2x"
                                                                                    style="width: 100%;color: #009aff">
                                        </i></a>
                                    <a href="{{url('user/work/task')}}"><span
                                                style="font-size: 20px;float: left;color: #009aff">&nbsp;任务管理</span></a>
                                    <div class="clear"></div>
                                </div>
                                <div class="col-lg-4 col-md-6 col-sm-12 col-xs-12 col-lg-offset-6 col-md-offset-4 btn-div">
                                    <button type="button" class="btn btn-info div-btn" data-toggle="modal"
                                            data-target="#modal-addMask"
                                            style="background: #009aff;float: right;margin-left: 1%;margin-top: 1%">新增任务
                                    </button>
                                    {{--<form action="{{url('user/work/taskSearch')}}" method="post"--}}
                                          {{--enctype="multipart/form-data" class="search">--}}
                                        {{--{{csrf_field()}}--}}
                                        {{--<input type="search" id="search-input" name="search">--}}
                                        {{--<button type="submit" class="fa fa-search fa-lg"></button>--}}
                                    {{--</form>--}}
                                </div>
                            </div>
                        </div>
                    </div>
                </div>
            </div>
            @include('public/alert')
            <div class="row" style="margin-left: 10px">
                <form class="form-inline" action="{{url('user/work/taskCertain')}}" method="post"
                      enctype="multipart/form-data">
                    {{csrf_field()}}
                    <div class="form-group">
                        <label for="exampleInputName2">申请人</label>
                        <input type="text" class="form-control" name="applicant" id="exampleInputName2" placeholder="申请人">
                    </div>
                    <div class="form-group">
                        <label for="exampleInputEmail2">公司</label>
                        <input type="text" class="form-control" name="company" id="exampleInputEmail2" placeholder="公司">
                    </div>
                    <label for="exampleInputName2">任务类型</label>
                    <select class="form-control" name="is_renew">
                        <option value=" " >不填</option>
                        <option value="0" >首次任务</option>
                        <option value="1" >续费任务</option>
                    </select>
                    <label for="exampleInputName2">类型</label>
                    <select class="form-control" name="first_type">
                        <option value=" " >不填</option>
                        <option value="1" >专利</option>
                        <option value="2" >商标</option>
                        <option value="3" >版权</option>
                        <option value="4" >项目</option>
                    </select>
                    <div class="form-group">
                        <label for="exampleInputName2">任务发起日期</label>
                        <input type="date" name="created_at" class="form-control" id="exampleInputName2" >
                    </div>
                    <label for="exampleInputName2">任务状态</label>
                    <select class="form-control" name="state">
                        <option value=" " >不填</option>
                        <option value="0" >未结算</option>
                        <option value="1" >未结单</option>
                        <option value="2" >操作中</option>
                        <option value="3" >结案</option>
                        <option value="4" >通过</option>
                    </select>
                    <label for="exampleInputName2">任务等级</label>
                    <select class="form-control" name="level">
                        <option value=" " >不填</option>
                        <option value="0" >普通任务</option>
                        <option value="1" >重要任务</option>
                        <option value="2" >紧急任务</option>
                    </select>
                    <button type="submit" class="btn btn-default">搜索</button>
                </form>
            </div>
            <div class="row" style="">
                <div class="col-lg-12 col-md-12 col-sm-12 col-xs-12">
                    <div class="table-responsive">
                        <table class="table table-bordered">
                            <thead>
                            <tr>
                                <th class="task-th">任务编号</th>
                                <th class="task-th">申请人</th>
                                <th class="task-th">公司</th>
                                <th class="task-th">任务类别</th>
                                <th class="task-th">类型</th>
                                <th class="task-th">任务发起时间</th>
                                <th class="task-th">任务状态</th>
                                <th class="task-th">任务等级</th>
                                <th class="task-th">执行人</th>
                                <th class="task-th">报件资料</th>
                                <th class="task-th">操作</th>
                            </tr>
                            </thead>
                            <tbody>
                            @if($product->isEmpty())
                                <tr>
                                    <td class="task-td" colspan="11"><h3 align="center">暂无数据</h3></td>
                                </tr>
                            @else
                                @php($i=0)
                                @foreach($product as $k =>$c)
                                    @php($v=$c['Product'])
                                    @if(!empty($c['FirstType']))
                                        <tr>
                                            <td class="task-td" style="vertical-align: middle">{{++$i}}</td>

                                            <td class="task-td" style="vertical-align: middle">{{$v['applicant']}}</td>
                                            <td class="task-td" style="vertical-align: middle">{{$v['company']}}</td>

                                            <td class="task-td" style="vertical-align: middle">
                                                @if($c['is_renew']==0)
                                                    首次任务
                                                @else
                                                    续费任务
                                                @endif
                                            </td>
                                            <td class="task-td"
                                                style="vertical-align: middle">{{$c['FirstType']['name']}}</td>
                                            <td class="task-td"
                                                style="vertical-align: middle">{{date("Y-m-d",strtotime($v['created_at']))}}</td>
                                            <td class="task-td"
                                                style="vertical-align: middle">{{config('config.product_state')[$c['state']]}}</td>
                                            <td class="task-td"
                                                style="vertical-align: middle">{{config('config.product_level')[$v['level']]}}</td>
                                            <td class="task-td" style="vertical-align: middle">
                                                @if(empty($c['agent']))
                                                    暂无
                                                @else
                                                    {{$c['agent']}}
                                                @endif
                                            </td>
                                            <td class="task-td" style="vertical-align: middle">
                                                @if(empty($v['file']))
                                                    未上传
                                                @else
                                                    <a href="{{asset('Uploads/resources/'.$v['file'])}}">查看资料</a>
                                                @endif
                                            </td>
                                            <td class="task-td" style="vertical-align: middle">
                                                @if($c['is_cancel']==config('config.mission_state_map.cancel'))
                                                    <a href="{{url('user/work/apply',['pid'=>$c['id'],'id'=>$v['id']])}}">重新申请</a>
                                                @else
                                                    <a href="#" data-toggle="modal" rel="{{$v['id']}}"
                                                       pid="{{$c['id']}}" onclick="setV($(this))"
                                                       data-target="#modal-upload-file">
                                                        @if(empty($v['file']))
                                                            上传资料
                                                        @else
                                                            重新上传
                                                        @endif
                                                    </a>
                                                    |  @if($c['first']==0&&$c['tail']==0)
                                                        <a href="{{url('user/work/setFund',['id'=>$c['id']])}}">
                                                            付首款</a>
                                                    @elseif($c['first']==1&&$c['tail']==0)
                                                        <a href="{{url('user/work/setFund',['id'=>$c['id']])}}">
                                                            付尾款
                                                        </a>
                                                    @else
                                                        <span> 已结清</span>
                                                    @endif

                                                    |
                                                    <a href="{{url('user/work/cancel',['pid'=>$c['id'],'id'=>$v['id']])}}">申请取消</a>
                                                @endif
                                            </td>
                                        </tr>
                                    @endif
                                @endforeach
                            @endif
                            </tbody>
                        </table>
                        <div class="">
                            {!! $product->links() !!}
                        </div>
                    </div>
                </div>
            </div>
        </section>
    </div>
    @include('public.addMaskModal')
    @include('public.upload-fileModal')
@stop
@section('javascript')
    <script src="{{asset('admin_assets/js/fileinput.min.js')}}"></script>
    <script src="{{asset('admin_assets/js/fileinput_locale_zh.js')}}"></script>
    <script src="{{asset('js/ip.js')}}"></script>
    <script>
        $("#inputFile").fileinput({
            language: 'zh',
            autoReplace: false,
            maxFileCount: 1,
            allowedFileExtensions: ["zip", "7z", "rar"],
            browseClass: "btn btn-primary",
            showUpload: false,
            showCancel: true,
            previewFileIcon: "<i class='glyphicon glyphicon-king'></i>"
        });
        $(getBusiness());

        function check() {
            return true;
        }

        function setV(e) {
            $('#pp').val(e.attr('pid'));
            $('#i').val(e.attr('rel'));
        }

        function getType(e) {
            $.ajax({
                url: '{{url('user/work/getSecondType')}}',
                type: 'post',
                dataType: 'json',
                data: {
                    'id': e.val()
                },
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    var type = $('#second_type');
                    type.empty();
                    var size = data.length;
                    if (size <= 0) {
                        type.append('<option value="-1">详细类型</option>');
                    } else {
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            type.append('<option value="' + item['id'] + '">' + item['name'] + '</option>');
                        }
                    }
                }
            })
        }

        function getBusiness() {
            $.ajax({
                url: '{{url('user/work/getBusiness')}}',
                type: 'post',
                dataType: 'json',
                headers: {
                    'X-CSRF-TOKEN': $('meta[name="_token"]').attr('content')
                },
                success: function (data) {
                    var type = $('#business_');
                    type.empty();
                    var size = data.length;
                    if (size <= 0) {
                        type.append('<option value="-1">详细类型</option>');
                    } else {
                        type.append('<option value="-1">业务员(可不选)</option>');
                        for (var i = 0; i < data.length; i++) {
                            var item = data[i];
                            type.append('<option value="' + item['id'] + '">' + item['real_name'] + '</option>');
                        }
                    }
                }
            })
        }
    </script>
@stop
